from typing import List, Union

from pydantic import BaseModel, Field

from apps.crawler_platform.core_platform.core_g import CoreSqlValue
from apps.crawler_platform.core_platform.g_model import OperatorSqlModel

headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
}


class UpdateTaskModel(BaseModel):
    basekey: dict = {}
    upset: list = []


class AddSqlModel(BaseModel):
    table: str = ""
    feild_dicts: dict = {}
    insert: str = CoreSqlValue.insert_it  # replace into
    # NO DUPLICATE KEY UPDATE
    ndku_feild: dict = {}


class AddManyModel(BaseModel):
    table: str = ""
    feild_list: List = []
    value_list: List = []
    insert: str = CoreSqlValue.insert_ig_it  # replace into


class UpdateSqlModel(BaseModel):
    table: str = ""
    update: dict = {}
    update_no_placeholder: dict = {}
    where: Union[dict, List[OperatorSqlModel]] = {}


class UpdateSqlListModel(BaseModel):
    data_list: List[UpdateSqlModel] = []


class UpdateSqlModelCtrl(BaseModel):
    task_name: str = ""
    task_tag: str = ""
    task_switch: str = "1"


class DeleteSqlModel(BaseModel):
    table: str = ""
    where: dict = {}


class ExecSqlModel(BaseModel):
    sql: str = ""
    is_dicts = False


class ExecManySqlModel(BaseModel):
    sql: str = ""
    value_list: list = []


class QuerySqlModel(BaseModel):
    table: str = ""
    field: str = ""
    where: dict = {}
    order: dict = {}
    limit: int = 0


class SaveMongoModel(BaseModel):
    id: str = ''
    table: str = ''  # 操作的mongodb表名
    is_his: str = 'False'  # 是否将new_data字段数据更新至history
    his_cnt: int = 0  # history保存最近记录的条数
    para: dict = {}  # {"id_list":["hh","jj"],"hh":"test","jj":"tag"},id_list为id组合顺序
    data: dict = {}  # 需要保存至mongo的数据
    data_op: int = 0  # 是否用data更新mongo里的new_data,0表示是,否则表示覆盖


class ResetMongoModel(BaseModel):
    id: str = ''
    table: str = ''


class SelectMongoModel(BaseModel):
    field: dict = {}
    table: str = ''
    and_param: dict = {}
    or_param: list = []
    order: list = []
    limit: int = 1


class SaveModel(BaseModel):
    id: str = Field("", alias="_id")
    last_data: dict = {}
    new_data: dict = {}
    history: list = []
    para: dict = {}
    update_time: str = ""
    create_time: str = ""


class SavePathModel(BaseModel):
    id: str = Field("", alias="_id")
    path: str = ""
    update_time: str = ""
    create_time: str = ""


class DownloadObjS3(BaseModel):
    url: str = ""
    file_dir: str = ""

class DownReportFile(BaseModel):
    url: str = ""
    task_name: str = ""
    task_tag: str = ""
    rawid: str = ""
    file_name: str = ""
    save_path: str = ""
    data_type: str = ""
    data_num: str = ""
    ext_name: str = ""
    data_dic: dict = {}
    proxy_type: str = "0"
    google_proxy: str = ""


class UpdateReportFile(BaseModel):
    # url: str = ""
    task_name: str = ""
    task_tag: str = ""
    rawid: str = ""
    file_type: str = ""
    is_success: str = ""